package smartcampus.scjava.controller.second;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import smartcampus.scjava.POJO.DTO.CourseDTO;
import smartcampus.scjava.custom.ResultVO;
import smartcampus.scjava.service.CourseService;

import java.util.List;

@RequestMapping("/course")
@RestController
@ApiOperation("学生课程表")
public class CourseController {

    @Autowired
    CourseService courseService;

    @GetMapping("/seletCouresList")
    @ApiOperation("根据学号查询一个学生的课程信息")
    public ResultVO<?> seletCouresList(String stuid) {
        List<CourseDTO> courseDTOList = courseService.seletCouresList(stuid);
        return ResultVO.success(courseDTOList);

    }

    @GetMapping("/seletAll")
    @ApiOperation("查询所有课程成绩")
    public ResultVO<?> seletAll(@RequestParam(defaultValue = "1") int pageNum,
                                @RequestParam(defaultValue = "10") int pageSize) {
        //利用pagehelper插件获取页面信息pagenum=第几页，pagesize=每页大小
        PageHelper.startPage(pageNum, pageSize);
        List<CourseDTO> courseDTOList = courseService.selectAll();
        PageInfo<CourseDTO> courseDTOPageInfo = new PageInfo<>(courseDTOList);
        return ResultVO.success(courseDTOPageInfo);
    }

}
